<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\links;
use DB;

class LinksController extends Controller
{
    public function index()
    {
      $links = DB::table('links')->orderBy('family')->get();
      return view('backend.link.index',compact('links'));
    }

    public function store(Request $request)
    {
      $this->validate($request,[
        'name'=>'required',
        'href'=>'required',
        'family'=>'required'
      ]);

      $links = links::create([
        'name'=> $request->name,
        'href'=> $request->href,
        'family'=> $request->family
      ]);
      session()->flash('success','链接创建成功！');
      return redirect()->back();
    }

    public function destroy($id)
  {

    $links = links::findOrFail($id);
    $links->delete();
    session()->flash('success','链接删除成功！');
    return redirect()->back();
  }
}
